/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.xtd.model.employment;

import com.xtd.model.settlement.Form;
import com.xtd.util.FormTypeEnum;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Lu Yuanbin
 */
@Entity
@Table(name = "payroll")
public class Payroll extends Form {

    @Column(name = "baseSalary")
    private BigDecimal baseSalary;
    @Column(name = "royalty")
    private BigDecimal royalty;
    @Column(name = "qualityService")
    private BigDecimal qualityService;
    @Column(name = "startDate")
    @Temporal(TemporalType.DATE)
    private Date startDate;
    @Column(name = "endDate")
    @Temporal(TemporalType.DATE)
    private Date endDate;
    @Column(name = "issueDate")
    @Temporal(TemporalType.DATE)
    private Date issueDate;
    @JoinColumn(name = "employee_id", referencedColumnName = "id", insertable = true, updatable = true)
    @ManyToOne
    private Employee employee;

    public Payroll() {
    }

    public Payroll(Employee employee, Date startDate, Date endDate, Employee createdBy) {
        this.employee = employee;
        this.royalty = BigDecimal.ZERO;
        this.startDate = startDate;
        this.endDate = endDate;
        setCreatedBy(createdBy);
        setCreatedTime(new Date());
        this.baseSalary = employee.getBaseSalary();
        this.setNumber("");
        this.setType(FormTypeEnum.薪酬);
        employee.getPayrollRecordCollection().add(this);
    }

    public BigDecimal getBaseSalary() {
        return baseSalary;
    }

    public void setBaseSalary(BigDecimal baseSalary) {
        this.baseSalary = baseSalary;
    }

    public BigDecimal getRoyalty() {
        return royalty;
    }

    public void setRoyalty(BigDecimal royalty) {
        this.royalty = royalty;
    }

    public BigDecimal getQualityService() {
        return qualityService;
    }

    public void setQualityService(BigDecimal qualityService) {
        this.qualityService = qualityService;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public Date getIssueDate() {
        return issueDate;
    }

    public void setIssueDate(Date issueDate) {
        this.issueDate = issueDate;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (getId() != null ? getId().hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Payroll)) {
            return false;
        }
        Payroll other = (Payroll) object;
        if ((this.getId() == null && other.getId() != null) || (this.getId() != null && !this.getId().equals(other.getId()))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.xtd.model.PaymentRecord[id=" + getId() + "]";
    }

    /**
     * @return the employee
     */
    public Employee getEmployee() {
        return employee;
    }

    /**
     * @param employee the employee to set
     */
    public void setEmployee(Employee employee) {
        this.employee = employee;
    }
}
